package com.wgtgt.multiplication;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

/**
 * Hello world!
 *
 */
public class App9 {
	public static void main(String[] args) {
		System.out.println("Hello World!");
		int n = 1;
		// ab * cd
		// 235种结果
		int last = 0;
		int count = 0;
		int f0 = 0;
		int f1 = 0;
		int ff = 0;
		int pf = 0;
		int g11 = 0;
		int g99 = 0;
		Map<Integer, Integer> map = new HashMap<Integer, Integer>();
		Map<Integer, List<Integer>> map2 = new HashMap<Integer, List<Integer>>();
		List<Integer> valueList = new ArrayList<Integer>();
		for (int a = 1; a <= 9; a++) {
			for (int b = 1; b <= 9; b++) {
				for (int c = 1; c <= 9; c++) {
					for (int d = 1; d <= 9; d++) {
						int ac = a * c;
						int ad = a * d;
						int bc = b * c;
						int bd = b * d;
						int e4 = bd % 10;
						int e3 = ad % 10 + bc % 10 + bd / 10;
						int e2 = ad / 10 + bc / 10 + ac % 10;
						int e1 = ac / 10;
						int ee3 = 0;
						int ee2 = e2 % 10;
						if (e3 >= 10) {
							ee3 = e3 / 10;
							if (ee2 + ee3 >= 10) {
								int ab = a * 10 + b;
								int cd = c * 10 + d;
								String numStr = n + "";
								if (n < 10) {
									numStr = "0" + n;
								}
								String str = ab + " * " + cd + " = " + (ab * cd);
								str = numStr + " " + str;
								if (ab >= cd) {
									if (ab != last) {
										str = str + " >> " + count;
										count = 0;
									} else {
										count++;
									}
									Integer value = map.get(ab);
									if (value == null) {
										map.put(ab, 1);
									} else {
										value++;
										map.put(ab, value);
									}
									int ji = ab * cd;
									int ji2 = ji / 100 % 10;
									if (ji2 == 0) {
										f0++;
									} else if (ji2 == 1) {
										f1++;
									} else {
										ff++;
									}
									if (ab == cd) {
										pf++;
									}
									if (ab == 11 || cd == 11) {
										g11++;
										System.out.println(str);
									}
									if (ab == 99 || cd == 99) {
										g99++;
									}
//									System.out.println(str);
									last = ab;
									n++;
								}
							}
						}
					}
				}
			}
		}

		System.out.println(map);
		Set<Entry<Integer, Integer>> entrySet = map.entrySet();
		for (Entry<Integer, Integer> entry : entrySet) {
			Integer key = entry.getKey();
			Integer value = entry.getValue();
			if (!valueList.contains(value)) {
				valueList.add(value);
			}
		}
		System.out.println(valueList);
		Set<Entry<Integer, Integer>> entrySet2 = map.entrySet();
		for (Entry<Integer, Integer> entry : entrySet2) {
			Integer key = entry.getKey();
			Integer value = entry.getValue();
			List<Integer> map2ValueList = map2.get(value);
			if (map2ValueList == null) {
				map2ValueList = new ArrayList<Integer>();
				map2ValueList.add(key);
				map2.put(value, map2ValueList);
			} else {
				map2ValueList.add(key);
				map2.put(value, map2ValueList);
			}
		}
		System.out.println(map2);
		System.out.println("f0=" + f0);
		System.out.println("f1=" + f1);
		System.out.println("ff=" + ff);
		System.out.println("pf=" + pf);
		System.out.println("g11=" + g11);
		System.out.println("g99=" + g99);
	}
}
